package kr.hkit.powerjava.chapter24.work2.service;

import java.util.Comparator;
import java.util.Scanner;

import kr.hkit.powerjava.chapter24.work2.dao.InterfaceDao;
import kr.hkit.powerjava.chapter24.work2.vo.Department;

public class DepartmentService extends ServiceItems<Department> {

	public DepartmentService(InterfaceDao<Department> dao, Scanner input) {
		super(dao, input);
	}

	@Override
	public Department inputItemInfo(boolean gubun) {
		System.out.println("부서번호 부서명");
		Department dept = new Department(input.nextInt(), input.next());
		System.out.println("위치");
		if(gubun) {
			dept.setFloor(input.nextInt());
		}
		return dept;
	}

	@Override
	public void prnSubMenu() {
		System.out.print("1.이름순 정렬 2.위치별 정렬 3.번호순 정렬");
		int res = input.nextInt();
		switch(res) {
			case 1:
				dao.prnItemList(new Comparator<Department>() {
					
					@Override
					public int compare(Department o1, Department o2) {
						return o1.getDeptName().hashCode()-o2.getDeptName().hashCode();
					}
				});
				break;
			case 2:
				dao.prnItemList(new Comparator<Department>() {

					@Override
					public int compare(Department o1, Department o2) {
						return o1.getFloor() - o2.getFloor();
					}
				});
		}
		
	}
	

}
